package com.kool.kadmin.system.controller;

import com.kool.kadmin.common.bean.ListResult;
import com.kool.kadmin.common.bean.Result;
import com.kool.kadmin.system.bean.SysMenuDo;
import com.kool.kadmin.system.request.*;
import com.kool.kadmin.system.service.MenuService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @author luyu
 */
@RestController
@Slf4j
public class MenuController {
    @Resource
    private MenuService menuService;

    /**
     * 查询用户有权限菜单
     *
     * @return
     */
    @RequestMapping("/menu/get_user_menus")
    public ListResult<SysMenuDo> getUserMenus(@Valid @RequestBody GetUserMenusReq request) {
        return menuService.getUserMenus(request);
    }

    /**
     * 查询菜单树
     *
     * @return
     */
    @RequestMapping("/menu/get_menu_tree")
    public ListResult<SysMenuDo> getMenuTree() {
        return menuService.getAllMenus();
    }

    /**
     * 增加菜单
     *
     * @return
     */
    @RequestMapping("/menu/add")
    public Result addMenu(@Valid @RequestBody AddMenuReq request) {
        return menuService.addMenu(request);
    }

    /**
     * 修改菜单
     *
     * @return
     */
    @RequestMapping("/menu/modify")
    public Result modifyMenu(@Valid @RequestBody ModifyMenuReq request) {
        return menuService.modifyMenu(request);
    }

    /**
     * 删除菜单
     *
     * @return
     */
    @RequestMapping("/menu/delete")
    public Result deleteMenu(@Valid @RequestBody DeleteMenuReq request) {
        return menuService.deleteMenu(request);
    }

    /**
     * 查询权限绑定的菜单
     *
     * @return
     */
    @RequestMapping("/menu/get_aut_menus")
    public ListResult<SysMenuDo> getAutMenus(@Valid @RequestBody GetAutMenusReq request) {
        return menuService.getAutMenus(request);
    }
}
